Employee Free Time
Question
Given a list of employee intervals representing the start and end times of their availability, find all the intervals of free time that are available for a meeting.
Example 1
Input
schedule: [[[1,2], [5,6]], [[1,3]], [[4,10]]]
Result
[[3,4]]
Solution
- ▭
- ▯
all//Employee Free Time.py
class Interval:
def __init__(self, start, end):
self.start = start
self.end = end
def employeeFreeTime(schedule):
# sort the schedule
schedule.sort(key=lambda x: x.start)
# find the free time
freeTime = []
end = schedule[0].end
for i in range(1, len(schedule)):
if schedule[i].start > end:
freeTime.append(Interval(end, schedule[i].start))
end = max(end, schedule[i].end)
return freeTime
all//Employee Free Time.py
class Interval:
def __init__(self, start, end):
self.start = start
self.end = end
def employeeFreeTime(schedule):
# sort the schedule
schedule.sort(key=lambda x: x.start)
# find the free time
freeTime = []
end = schedule[0].end
for i in range(1, len(schedule)):
if schedule[i].start > end:
freeTime.append(Interval(end, schedule[i].start))
end = max(end, schedule[i].end)
return freeTime